﻿/**
 * Jean-François Desgagné 2009 Portfolio
 * Copyright (c) 2009 Jean-François Desgagné <jfesgagne@gmail.com>
 * 
 * This work is licensed under a Creative Commons Attribution 3.0 United States License.
 * Some Rights Reserved.
 */
package com.jfdesgagne.jfdesgagne09.modules.showcase.view {
    import com.jfdesgagne.jfdesgagne09.modules.showcase.ApplicationFacade;
    import com.jfdesgagne.jfdesgagne09.modules.showcase.view.component.SlideshowItem;
	import com.jfdesgagne.jfdesgagne09.modules.showcase.view.component.Slideshow;
	import com.jfdesgagne.jfdesgagne09.shell.view.LoadingMediator;
	
	import org.puremvc.as3.multicore.interfaces.*;
    import org.puremvc.as3.multicore.patterns.mediator.Mediator;
    
    public class SlideshowMediator extends Mediator implements IMediator {
        // Cannonical name of the Mediator
        public static const NAME:String = "SlideshowMediator";

        public function SlideshowMediator(viewComponent:Object) {
			super(NAME, viewComponent);
			trace("SlideshowMediator")
        }
		
		public static function getInstance():SlideshowMediator {
			return ApplicationFacade.getInstance(ApplicationFacade.NAME).retrieveMediator(SlideshowMediator.NAME) as SlideshowMediator;
		}
		
		override public function listNotificationInterests():Array {
            return [ 
            		ApplicationFacade.INITIALIZE,
					ApplicationFacade.IMAGESLOAD_COMPLETE,
					ApplicationFacade.IMAGELOAD_PROGRESS
                   ];
        }

        override public function handleNotification(note:INotification):void {
            switch (note.getName()) {
            	case ApplicationFacade.INITIALIZE:    	
					trace("slideshow initialisated");
				break;
				
				case ApplicationFacade.IMAGESLOAD_COMPLETE:
					trace("IMAGESLOAD_COMPLETE");
					this._show();
				break;
				
				case ApplicationFacade.IMAGELOAD_PROGRESS:
					trace("IMAGELOAD_PROGRESS");
					LoadingMediator.getInstance().percent = note.getBody() as Number;
				break;
            }
        }
        
		private function _show():void {
			trace("slide show is loaded and ready to show");
		}
		
		public function get slideshow():Slideshow {
            return this.viewComponent as Slideshow;
        }
    }
}